package com.live.video.websocket;

import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import java.util.Map;

/**
 * Description:
 * User: godd
 * Date: 2017-10-12
 * Time: 下午2:38
 */
public class HandShkeInceptor extends HttpSessionHandshakeInterceptor {

    /**
     * 握手前拦截非法用户
     *
     * @author 戴长春    dcc@vtc365.com
     * @date 2017/10/12 下午2:40
     */
    @Override
    public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
        System.out.println("握手前:"+request.getURI()+",IP:"+request.getRemoteAddress());

        if(request instanceof ServletServerHttpRequest){
            ServletServerHttpRequest _request = (ServletServerHttpRequest) request;
        }

        return super.beforeHandshake(request, response, wsHandler, attributes);
    }

    @Override
    public void afterHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Exception ex) {
        super.afterHandshake(request, response, wsHandler, ex);
    }
}
